﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Tests.Basics.UI {
	/// <summary>
	/// Interaction logic for ThumbnailsViewer.xaml
	/// </summary>
	public partial class ThumbnailsViewer : Window {
		public ThumbnailsViewer() {
			InitializeComponent();
			LoadImags ();
		}

		private void LoadImags () {
			var dlg = new OpenFileDialog();
			dlg.Multiselect = true;
			dlg.FileName = "files to display"; // Default file name
			dlg.DefaultExt = ".jpg"; // Default file extension
			dlg.Filter = "Images (.jpg)|*.jpg"; // Filter files by extension
			if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
				List<DataStructure> data = new List<DataStructure>();
				int index = 0;
				var filenames = dlg.FileNames.OrderBy (x => x).ToArray();
				foreach (var img in filenames) {
					index++;
					data.Add(new DataStructure {
					                           	Frame = index.ToString("Frame 000"),
					                           	Image = new BitmapImage(new Uri(img, UriKind.Absolute))
					                           });
				}
				m_items.ItemsSource = data;
			}
			else {
				Close();
			}
		}

		private void Button_Click(object sender, RoutedEventArgs e) {
			LoadImags ();
		}
	}
	public class DataStructure {
		public ImageSource Image { get; set; }
		public String Frame { get; set; }
	}
}
